<?php

class HistoryFuncs extends Module
{
    const PAGE_NUM = 25;
    function __construct()
    {
    }    
    private static $_obj = null;
    static function getInstance()
    {
        if( !self::$_obj )
        {
            self::$_obj = new self();
        }

        return self::$_obj;
    }
    
    function getTools()
    {
        $dir = BASE_PATH.'/Module/';        
        $modules = array();
        $files = scandir( $dir );

		$escape = array( '', 'Module', 'Home', 'Funcs' );
        foreach( $files as $file )
        {
            if( substr( $file, -4) != 'php1' ) continue;
			$arr = explode( '.', $file ); 
			if( in_array( $arr[0], $escape ) )
			{
				continue;
			}

            $file = $dir . $file;
			if( !preg_match( '/^[a-zA-Z]*\.[PHph1]*$/', basename($file) ) )
			{
				continue;
			}
            if( is_file( $file ) && ( $name = $this->isOkModule( $file ) ) )
            {
                $modules[] = $name;
            }
        }

        return $modules;
    }
    
    private function isOkModule( $file )
    {
		if( ! is_file( $file ) )
		{
			$this->info( " can't find {$file}. " );
			return false;
		}
        require_once $file;
        $fileName = basename( $file );
        $fileInfo = explode( '.', $fileName );
        $name = $fileInfo[0];
        if( class_exists( $name ) 
            && method_exists( $name, 'display' ) )
        {
            return $name;
        }
        return false;
    }

    function display()
    {
        $funcs = $this->getTools();
        parent::smartyOut('historyfuncs', array( 'ret'=>true, 'data'=>$funcs) );
    }
}
























